package history.double_exam;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

// 5212. 向下取整数对和
public class LeetCode_5212 {
    public static void main(String[] args) {
        sumOfFlooredPairs(new int[]{4,3,4,3,5});
    }
    public static int sumOfFlooredPairs(int[] nums) {
        if (nums == null || nums.length <=0) return 0;
        int length = nums.length;
        Arrays.sort(nums);
        long result = length;

        List<Integer> someNumberTimeList = new ArrayList<>();
        int lastSameNumberTime = 0;
        for (int i = 0; i < nums.length-1; i++) {
            if (nums[i]==nums[i+1]) {
                lastSameNumberTime++;
            } else if (lastSameNumberTime>0){
                someNumberTimeList.add(lastSameNumberTime);
                lastSameNumberTime = 0;
            }
        }
        if (lastSameNumberTime >0) someNumberTimeList.add(lastSameNumberTime);

        for (int i =0; i < length-1; i++) {
            for (int j = i+1; j < length;j++) {
                result += nums[j]/nums[i];
            }
        }

        for (Integer integer: someNumberTimeList) {
            long number = 0;
            for (int i = 1; i <= integer; i++ ) {
                number += i;
            }
            result += number;
        }
        return (int)(result %(Math.pow(10,10)+7));
    }
}
